#include <stdio.h>
#include <stdlib.h>
#include "undirected-graph.h"

int n, m;
UGraph *g;
double result[1001];

void readGraph() {
  int i, x, y;
  double cost;

  scanf(" %d %d", &n, &m);

  for(i=0; i<m; i++) {
    scanf(" %d %d %lf", &x, &y, &cost);
    addEdge(g, x, y, cost);
  }

}

int main() {
  int i, j, localMax, globalMin = INF;
  g = newUGraph();

  readGraph();

  for(i=0; i<g->size; i++) {
    dijkstra(g, g->used[i], result);
    localMax = 0;
    for(j=0; j<g->size; j++) {
      if( result[g->used[j]] > localMax )
        localMax = result[g->used[j]];
    }
    if (localMax < globalMin)
      globalMin = localMax;
  }

  printf("%d\n", globalMin);
  return 0;
}
